﻿namespace Sunny.Service
{
    /// <summary>
    /// Json返回类
    /// </summary>
    public class Result
    {
        public int Code { get; set; } = 0;
        public string Message { get; set; }
        public object Data { get; set; }

        private Result(object data)
        {
            this.Code = 0;
            this.Message = "success";
            this.Data = data;
        }

        private Result(int code, string message)
        {
            this.Code = code;
            this.Message = message;
        }


        public static Result Success()
        {
            return new Result(data: null);
        }

        public static Result Success(object data)
        {
            return new Result(data);
        }

        public static Result Error(CodeMessage codeMessage)
        {
            return new Result(codeMessage.Code, codeMessage.Message);
        }

        public static Result Error(string message)
        {
            return new Result(-1, message);
        }
    }
}